package two.chapter_1.c1_4;

import edu.princeton.cs.algs4.StdOut;
import two.chapter_1.c1_3.LinkStack;
import two.chapter_1.c1_3.LinkedQueue;
import two.chapter_1.c1_3.Queue;
import two.chapter_1.c1_3.Stack;

import java.util.Iterator;

public class Ex1_4_28 {


    public static void main(String[] args) {

        QueueImplStack<String> stack=new QueueImplStack<>();
        stack.push("g");
        stack.push("f");
        stack.push("e");
        stack.push("d");
        stack.push("c");
        stack.push("b");
        stack.push("a");

        while (!stack.isEmpty()){
            StdOut.print(stack.pop());
        }
    }



    private static class QueueImplStack<Item> extends Stack<Item>{
        private Queue<Item> queue;

        public QueueImplStack(){
            queue=new LinkedQueue<>();
        }
        @Override
        public void push(Item item) {
            queue.enqueue(item);
        }

        @Override
        public boolean isEmpty() {
            return queue.isEmpty();
        }

        @Override
        public Item pop() {

            for (int i=0;i<queue.size()-1;i++){
                queue.enqueue(queue.dequeue());
            }

            return queue.dequeue();
        }

        @Override
        public Item peek() {
            return null;
        }

        @Override
        public Iterator<Item> iterator() {
            return null;
        }
    }


}
